#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/string_ext"
require "#{LKP_SRC}/lib/tests/stats"

stats = LKP::Stats.new

while (line = $stdin.gets)
  line = line.resolve_invalid_bytes

  case line
  when /\d*(not ok|ok).* - (.*) # (SKIP)/
    # [   41.553449]     ok 7 - pagealloc_oob_right # SKIP Test requires CONFIG_KASAN_GENERIC=n
    stats.add_test_result line, $2, $3
  when /\d*(not ok|ok).* - (.*)/
    # [   41.553190]     ok 6 - kmalloc_pagealloc_invalid_free
    # there are two "ok 1 - total_mapping_size_test" in output
    stats.add_test_result line, $2, $1 unless stats.key? $2.to_s
  end
end

stats.dump
